package com.shy.servicebase.ExceptionHandler;

import com.shy.commonutils.result.R;
import com.shy.servicebase.GlobalException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created with Intellij IDEA.
 *
 * @Author: RinMi
 * @Date: 2022/08/18/21:55
 * @Description:
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.error();
    }
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public R error(ArithmeticException e){
        e.printStackTrace();
        return R.error().message("执行了自定义异常");
    }
    @ExceptionHandler(GlobalException.class)
    @ResponseBody
    public R error(GlobalException e){
        e.printStackTrace();
        return R.error().message(e.getMsg()).code(e.getCode());
    }

}